<div class="col-md-8">
<div class="main-content" id="main-content">
	<div class="sub-content">
		<div class="top-header page-header clearfix">
			
				<h1>Buys List</h1>

		</div>
		<div class="product_table table-responsive">
			<p id="messageStatus" style="color:green;display:none">Succussesfully chage the status.</p>
			<table cellpadding="0" cellspacing="0" id="search_results" class="table table-bordered table-hover">
			   <thead>
				<tr class="bg_header">
					<td>SNO</td>
					<td>User Name</td>
					<td>Product Name</td>
					<td>Quantity</td>
					<td>Actual Price</td>
					<td>Status</td>
					<!--<td>Action</td>-->
					<td>History</td>
				</tr>
			   </thead>
			</table>
		</div>
		<div class="adding_list form-group">
			<div class="botton_btns">
				<div class="spacer20">&nbsp;</div>
						<div class="spacer20">						
					<a class="btn btn-danger" role="button" href="<? echo $this->Url('products')?>/buy-received-products">Back</a>
				</div>
			</div>
		</div>
	</div>
</div> </div>
<input type="hidden" name="hid_product_id" id="hid_product_id" value="<?php if(isset($_GET['product'])){ echo $_GET['product'];}?>"/>
<script>
$(function(){
var buy_product=$("#hid_product_id").val();
	$.ajax({
		type:	'GET',
		dataType:'json',
		url:BASE_PATH+'/products/buy-detailes-ajax?buy_product='+buy_product,
		success: function(data){
		eval(data);
		var oTable = $('#search_results').dataTable( {
					aoColumnDefs: [{bSortable: false,
									aTargets: [ 0 ]
									}],
					"bStateSave": true,
					"bAutoWidth": true,
					"sRowSelect": "multi",
					"sPaginationType": "full_numbers",
					"bProcessing": true,
 					"aaData": data,
					"aoColumns": [
						{ "mData": "sno" },
						{ "mData": "companyname" },
						{ "mData": "genericname" },
						{ "mData": "order_for_quantity" },
						{ "mData": "order_for_price" },
						{ "mData": "status" },
						//{ "mData": "action" },
						{ "mData": "history" },
					] 
				});			
		}
	});
});
function viewHistory(buy_id){
	var backId=$('#hid_product_id').val();
	window.location=BASE_URL+"/view-history?product="+buy_id+"&id="+backId+"&type=buy";				
}
function changeStatus(buy_id){
	var newStatus=$('#status'+buy_id).val();
	/*$.ajax({
		type:'POST',
		url:BASE_PATH+'/change-status-orders',
		data:{id:buy_id,newStatus:newStatus,type:'buy'},
		success: function(data){
			if(data.output=='success'){	
				$('#messageStatus').show().delay(4000).fadeOut();;
			}
		}
	});*/
	window.location=BASE_URL+"/products/update-product-status?buy_id="+buy_id+"&status="+newStatus+"&type=buy";	
}
</script>